package com.saint.farmshop.Controller;

import com.saint.farmshop.Dto.ArticleDto;
import com.saint.farmshop.Entity.Article;
import com.saint.farmshop.Service.ServiceImpl.ArticleServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.util.List;

/**
 * 文章控制器
 *
 * @author Saint
 * @date 2022/05/30
 */
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Resource
    private ArticleServiceImpl articleService;

    @RequestMapping("/getArticleList/{pageNum}")
    List<ArticleDto> getArticleList(@PathVariable("pageNum") Integer pageNum, @RequestParam Integer pageSize) {
        return articleService.getArticleList(pageNum, pageSize);
    }

    @RequestMapping("/getArticleById")
    ArticleDto getArticleById(@RequestParam String id) {
        return articleService.getArticleById(id);
    }

    @RequestMapping("/addArticle")
    Article addArticle(@RequestBody Article article) {
        return articleService.addArticle(article);
    }

    @RequestMapping("/updateArticle")
    Article updateArticle(@RequestBody Article article) {
        return articleService.updateArticle(article);
    }

    @RequestMapping("/deleteArticle")
    boolean deleteArticle(@RequestParam String id) {
        return articleService.deleteArticle(id);
    }
}
